# Maintainer: Andreas Radke <andyrtr@archlinux.org>
# Contributor: Stéphane Gaudreault <stephane@archlinux.org>
# Contributor: SleepyDog

pkgname=glew
pkgver=2.2.0
pkgrel=6
pkgdesc="The OpenGL Extension Wrangler Library"
arch=('x86_64')
url="https://github.com/nigels-com/glew"
license=('BSD' 'MIT' 'GPL')
depends=('glibc' 'libegl' 'libgl' 'glu')
optdepends=('libx11: for glxewinfo and visualinfo')
provides=('libGLEW.so')
# https://sourceforge.net/projects/glew/files/glew/
source=(https://downloads.sourceforge.net/${pkgname}/${pkgname}-${pkgver}.tgz
        glew-install.patch
        egl+glx.patch)
sha1sums=('22d6e9b9e691080eb6313407dbf51cfebc3345ea'
          'e1bfa1e6ae3c7a553920978111092ea9d3a33c95'
          '30dbb0a98883db63414d41114aacc9f847edd066')
sha256sums=('d4fc82893cfb00109578d0a1a2337fb8ca335b3ceccf97b97e5cc7f08e4353e1'
            'ef864c1e673f6a8fab4d3f5bc3c3eb9596cd225c24765de9dff2064e72f350d5'
            '206dc53e185aa2bd64b21107dcaafccb3207a8185ccd1c02a87ed9783c25cc61')

prepare() {
  cd ${pkgname}-${pkgver}
  
  patch -Np1 -i ../glew-install.patch
  patch -Np1 -i ../egl+glx.patch
  
  sed -i 's|lib64|lib|' config/Makefile.linux
  sed -i '/^.PHONY: .*\.pc$/d' Makefile
}

build() {
  cd ${pkgname}-${pkgver}

  make STRIP= glew.bin
  mv bin/glewinfo bin/glxewinfo
  rm glew.pc
  
  make STRIP= SYSTEM=linux-egl glew.lib.shared bin/glewinfo
  mv bin/glewinfo bin/eglewinfo
}

package() {
  cd ${pkgname}-${pkgver}
  
  make GLEW_DEST="${pkgdir}/usr" STRIP= SYSTEM=linux-egl install
  install -D -m755 -t "${pkgdir}/usr/bin" bin/eglewinfo bin/glxewinfo bin/visualinfo
  ln -s eglewinfo "${pkgdir}/usr/bin/glewinfo"
  
  install -D -m644 LICENSE.txt "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
